from flask import render_template, jsonify
from sqlalchemy import select
from models import Books

from app import app, db


@app.route('/')
def index():
    return render_template('index.html')


@app.route('/books')
def get_books():
    result = db.session.execute(select(Books)).scalars().all()
    books_list = []
    for book in result:
        books_list.append(book.to_json())
    return render_template('books_list.html', books=books_list)
